package ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import td.TwoTower;

/*
 * View class to represent Two Towers on the map.
 * */
public class TwoTowerView extends TowerView{

	public TwoTowerView(TwoTower tt){
		super(tt);
		this.setLayout(new GridBagLayout());
		/*Sets the displayable image.*/
		image = Toolkit.getDefaultToolkit().getImage("Images/twotower.png");
		update();
	}
	
	@Override
	public void update(){
		this.removeAll();
		GridBagConstraints gridc = new GridBagConstraints();
		gridc.gridx = 0;
		gridc.gridy = 0;
		/*Checks if the tower has an upgrade stone in the 
		 * first slot and sets displayable image.*/
		if(((TwoTower)fieldElement).stones[0]!=null){
			gridc.anchor = GridBagConstraints.LAST_LINE_START;
			Image stone = null;
			switch(((TwoTower) fieldElement).stones[0]){
			case Blue:
				stone = Toolkit.getDefaultToolkit().getImage("Images/blue.png");
				break;
			case Red:
				stone = Toolkit.getDefaultToolkit().getImage("Images/red.png");
				break;
			case Yellow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/yellow.png");
				break;
			case Rainbow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/rainbow.png");
				break;
			}
			JLabel picLabel = new JLabel(new ImageIcon(stone));
			add(picLabel, gridc);
		}
		/*Checks if the tower has an upgrade stone in the 
		 * second slot and sets displayable image.*/
		if(((TwoTower)fieldElement).stones[1]!=null){
			gridc.anchor = GridBagConstraints.LAST_LINE_END;
			Image stone = null;
			switch(((TwoTower) fieldElement).stones[1]){
			case Blue:
				stone = Toolkit.getDefaultToolkit().getImage("Images/blue.png");
				break;
			case Red:
				stone = Toolkit.getDefaultToolkit().getImage("Images/red.png");
				break;
			case Yellow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/yellow.png");
				break;
			case Rainbow:
				stone = Toolkit.getDefaultToolkit().getImage("Images/rainbow.png");
				break;
			}
			JLabel picLabel = new JLabel(new ImageIcon(stone));
			add(picLabel, gridc);
		}
		/*Puts up fog on the tower if there was a fog event*/
		gridc.anchor = GridBagConstraints.CENTER;
		if(((TwoTower)fieldElement).fogged){
			JLabel fogLabel = new JLabel(new ImageIcon(fogImage));
			add(fogLabel,gridc);
		}
		/*Puts up picture of the tower*/
		JLabel picLabel = new JLabel(new ImageIcon(image));
		add(picLabel,gridc);
	}

}
